package br.cin.stadium.application;

import java.util.ArrayList;

import android.util.Log;
import br.cin.stadium.middleware.StadiumTS;
import br.cin.stadium.middleware.media.Media;
import br.cin.stadium.middleware.media.MediaReference;




public class ClientBehaviour
{
	public void execute()
	{
		// CLIENTE 
		// read all media from section 1 or with "goal1" name
		ArrayList<MediaReference> arraymRef = null;

		try {
			arraymRef = StadiumTS.getInstance().readAll(); // read all medias
			Media media = null;
			if (arraymRef != null)
			{
				for (MediaReference mediaReference : arraymRef)
				{
					Log.i("TEST", "Media " + mediaReference.getMediaName());
					// select a specific media, e.g. the first one
					media = StadiumTS.getInstance().requestMedia(mediaReference);
					// use the media
					Log.i("TEST","Name: " + media.getName() + " |Type: " + media.getType() + " |Sector: " + media.getStadiumSector() + " |Content: " + media.getContent());
				}		
			}		
			StadiumTS.getInstance().unRegisterUnit();
			
		} catch (Exception e) {
			// TODO: handle exception
		}
		
//		// read all media from section 1 or with "goal1" name
//		ArrayList<MediaReference> arraymRef = null;
//
//		arraymRef = StadiumTS.read(1); // read by stadium section
//		// or
//		arraymRef = StadiumTS.read("goal1"); // read by media name
//
//		if (arraymRef != null)
//		{
//			for (MediaReference mediaReference : arraymRef)
//			{
//				System.out.println("Media " + mediaReference.getMediaName() + " on ip " + mediaReference.getIp());				
//			}
//			
//			Media media = null;
//
//			// select a specific media, e.g. the first one
//			media = StadiumTS.requestMedia(arraymRef.get(0));
//
//			// use the media
//			System.out.println("media name: " + media.getName());
//			System.out.println("media type: " + media.getType());
//			System.out.println("media sector: " + media.getStadiumSector());
//			System.out.println("media content: " + media.getContent());
//		}
	}
}
